/*
 * Option.java
 *
 * Created on May 15, 2008, 2:11 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package morseme;

/**
 *
 * @author tt
 */
import javax.microedition.lcdui.*;

public class Option extends Form implements CommandListener{

private static String[] opts = {"On", "Off"};
private static Command okCmd = new Command("OK", Command.OK, 0);
private static Command cancelCmd = new Command("Cancel", Command.CANCEL, 1);
private ChoiceGroup soundGroup = new ChoiceGroup("Sound", ChoiceGroup.EXCLUSIVE, opts, null);
private ChoiceGroup vibrateGroup = new ChoiceGroup("Vibration", ChoiceGroup.EXCLUSIVE, opts, null);
private ChoiceGroup autoGroup = new ChoiceGroup("Auto Play", ChoiceGroup.EXCLUSIVE, opts, null);
private TextField numAutoTF = new TextField("Number of Auto Play : ", "1", 160, TextField.DECIMAL);

private MainMenu menu;
public static int SOUND_SEL = 0;
public static int VIBRATION_SEL = 0;
public static int AUTO_SEL = 0;
public static int NUM_AUTO_PLAY = 1;

public Option(MainMenu menu) {

super("Setting");
this.menu = menu;

this.addCommand(okCmd);
this.addCommand(cancelCmd);
this.setCommandListener(this);

this.append(soundGroup);
this.append(vibrateGroup);
this.append(autoGroup);
this.append(numAutoTF);

SOUND_SEL = soundGroup.getSelectedIndex();
VIBRATION_SEL = vibrateGroup.getSelectedIndex();
AUTO_SEL = autoGroup.getSelectedIndex();
NUM_AUTO_PLAY = Integer.parseInt(numAutoTF.getString());

}

protected void refresh(){

soundGroup.setSelectedIndex(SOUND_SEL, true);
vibrateGroup.setSelectedIndex(VIBRATION_SEL, true);
autoGroup.setSelectedIndex(AUTO_SEL, true);
numAutoTF.setString(Integer.toString(NUM_AUTO_PLAY));
}

public void commandAction(Command c, Displayable d){

if(c == okCmd){

SOUND_SEL = soundGroup.getSelectedIndex();
VIBRATION_SEL = vibrateGroup.getSelectedIndex();
AUTO_SEL = autoGroup.getSelectedIndex();
NUM_AUTO_PLAY = Integer.parseInt(numAutoTF.getString());
}

Display.getDisplay(MorseME.getMIDlet()).setCurrent(this.menu);
}
}

